// Copyright 2008-2009 Louis DeJardin - http://whereslou.com
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
using System;
using System.Web;
using System.Collections.Generic;
using Spark;

namespace NRails.Tests.Spark
{
	public class Comment
	{
		public Text : string { get; set; }
	}
    
    public abstract class StubSparkView : SparkViewBase
    {
        protected this()
        {
            ViewData = StubViewData();
        }

        public ViewData  : StubViewData  { get; set; }

        public SiteRoot : string 
        {
            get { "/TestApp"; }
        }

        public SiteResource(path : string ) : string 
        {
            SiteRoot + path.TrimStart('~');
        }

        public override TryGetViewData(name : string , mutable value : out object) : bool 
        {
            ViewData.TryGetValue(name, out value);
        }

        public  H(content : object ) : object
        {
            content;
        }

        public HTML(content : object) : object 
        {
            HttpUtility.HtmlEncode(Convert.ToString(content)) : object;
        }

        public Eval(expression : string) : object
        {
            ViewData.Eval(expression);
        }
    }

    public abstract class StubSparkView[TModel] : StubSparkView
    {
        public new ViewData : StubViewData[TModel]
        {
            get { base.ViewData :> StubViewData[TModel]; }
            set { base.ViewData = value; }
        }
    }
    
    public class StubViewData : Dictionary[string, object]
    {
        public Eval(key : string ) : object 
        {
            mutable value : object;
            if (TryGetValue(key, out value)) value else null;
        }
    }

    public class StubViewData[TModel] : StubViewData
    {
        public Model : TModel { get; set; }
    }

}
